﻿using AutoMapper;
using SIG.Model.Ads;
using SIG.Service;
using SIG.ViewModel.Front.Ads;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace SIG.WebMVC.Controllers
{
    public class CarouselController : Controller
    {
        private readonly ICarouselService _carouselService;
        private readonly IPositionService _positionService;
        private readonly IMapper _mapper;
        public CarouselController(ICarouselService carouselService, IPositionService positionService, IMapper mapper)
        {
            _carouselService = carouselService;
            _positionService = positionService;
            _mapper = mapper;
        }

       
        // GET: Carousel
        public PartialViewResult Carousels(string code)
        {
            var position = _positionService.GetPositionByCode(code);

            if (position == null)
            {
                TempData["Error"] = $"{code}广告位不存在！";
                return PartialView("_Carousels", null);
            }
            else
            {
                var carousels = _carouselService.GetCarouselsByPositionId(position.Id);
                var list = _mapper.Map<IEnumerable<Carousel>, IEnumerable<CarouselVM>>(position.Carousels.OrderByDescending(m => m.Importance));
                return PartialView("_Carousels", list);
            }
            
         
        }
    }
}